import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Word {
	String translated, english;

	public Word(String translated, String english) {
		this.translated = translated;
		this.english = english;
	}
}

class AvlNode {
	AvlNode right, left, p;
	int height;
	Word key;

	public AvlNode(AvlNode right, AvlNode left, AvlNode p, int height, Word key) {
		this.height = height;
		this.key = key;
		this.left = left;
		this.p = p;
		this.right = right;
	}
}

class AvlTree {
	AvlNode root = null;

	private int max(int n1, int n2) {
		if (n1 > n2)
			return n1;
		return n2;
	}

	public AvlNode search(String translated) {
		AvlNode actual = root;
		while (actual != null && !actual.key.translated.equals(translated)) {
			if (translated.compareTo(actual.key.translated) > 0) {
				actual = actual.right;
			} else {
				actual = actual.left;
			}
		}
		return actual;
	}

	public void insert(Word element, AvlNode n) {
		if (root == null) {
			root = new AvlNode(null, null, null, 1, element);
			return;
		}

		if (element.translated.compareTo(n.key.translated) > 0) {
			if (n.right == null) {
				n.right = (new AvlNode(null, null, n, 1, element));
				fixHeight(n.right);
			} else {
				insert(element, n.right);
			}
		}

		else if (element.translated.compareTo(n.key.translated) < 0) {
			if (n.left == null) {
				n.left = (new AvlNode(null, null, n, 1, element));
				fixHeight(n.left);
			} else {
				insert(element, n.left);
			}
		}
	}

	private void fixHeight(AvlNode n) {
		if (n == null)
			return;
		if (n.right == null) {
			if (n.left == null) {
				n.height = 1;
			}
		} else if (n.left == null) {
			n.height = n.right.height + 1;
		} else {
			n.height = max(n.right.height, n.left.height);
		}
		fixHeight(n.p);
	}

	public void reestructure() {
		//change to private
	}
}

public class Main {

	public static void main(String[] args) {
		BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
		AvlTree dictionary = new AvlTree();

		// put words in the tree
		String text = "-";
		while (true) {
			try {
				text=read.readLine();
			} catch (IOException e) {
			}
			if (text.equals("")) break;
			String[] parts = text.split(" ");
			dictionary.insert(new Word(parts[1], parts[0]), dictionary.root);
		}
		
		// get and print the message 
		text = "-";
		while (true) {
			try {
				text=read.readLine();
			} catch (IOException e) {
			}
			if (text.equals("")) break;
			
			try {
				System.out.println(dictionary.search(text).key.english);
			} catch (Exception e) {
				System.out.println("eh");
			}
			
		}

	}
}
